fix(expect): guard property definitions to avoid “Cannot redefine property” error#1881
fix(expect): guard property definitions to avoid “Cannot redefine property” error#1881JustasMonkev wants to merge 3 commits intowebdriverio:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds idempotent initialization for soft assertion helpers on the expect object by checking for existing properties before defining them.
- Introduces a
SoftHelperstype andhelperFactoriesobject to centralize soft assertion methods. - Replaces repeated
Object.definePropertycalls with a loop that guards against redefinition. - Updates the
expectWithSoftcast to includeSoftHelpers.
Comments suppressed due to low confidence (1)
src/index.ts:57
- Consider adding a unit test that re-invokes this setup logic and asserts no errors are thrown and that helpers remain defined, to verify idempotency.
for (const [name, fn] of Object.entries(helperFactories)) {
|
@JustasMonkev thanks for raising the PR! I've been working on webdriverio/webdriverio#14592 to get this fixed. The problem is that we shouldn't load I will keep this PR open for now but above PR should fix this. |
|
Closing as PR was merged and published. |
Checks for existing keys before calling
Object.definePropertyto avoid
“Cannot redefine property”errors when the module isevaluated multiple times or multiple SoftAssertionService
instances run in the same process.
This makes
expect.softand its utility methods idempotent and prevents startup crashes.